<template>
  <div class="divBox relative">

    <el-card class="box-card" style="min-height: 80vh">
      <div slot="header" class="clearfix" style="margin-bottom: -20px ;">
        <div class="container">

          <el-form :inline="true" :model="queryForm" @submit.native.prevent>

            <el-form-item>
              <el-radio-group  v-model="queryForm.userexist" size="small" @change="search">
                <el-radio-button  label="0" >真实</el-radio-button>
                <el-radio-button  label="1" >虚拟</el-radio-button>
              </el-radio-group>
            </el-form-item>
            <el-form-item>
              <el-input v-model="queryForm.userniname" placeholder="请输入用户名" clearable @keyup.enter.native="search()"></el-input>
            </el-form-item>
            <el-form-item>
              <el-form-item>
                <el-select v-model="queryForm.audit" placeholder="请选择审核状态" class="width100" filterable clearable>
                  <el-option label="正常" key="0" value="0"></el-option>
                  <el-option label="封禁" key="1" value="1"></el-option>
                </el-select>
              </el-form-item>
            </el-form-item>
            <el-form-item>
              <el-button @click="search()">查询</el-button>
              <el-button v-if="checkPermi(['userentity:index:save'])" type="primary" @click="addOrUpdateHandle()">新增</el-button>
              <el-button v-if="queryForm.userexist==1"  type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">删除</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <el-table  :data="dataList" v-loading="dataListLoading" @selection-change="selectionChangeHandle" style="width: 100%;"
                 size="mini" :highlight-current-row="true" :header-cell-style=" {fontWeight:'bold'}">
        <el-table-column type="selection" header-align="center" align="center" width="50"/>
        <el-table-column prop="cid" label="朋友圈id" :show-overflow-tooltip="true" width="160"></el-table-column>
        <el-table-column prop="userniname" label="用户名"  min-width="120">

          <template slot-scope="scope"  >
            <span v-if="scope.row.userexist==0">{{scope.row.userniname}}</span>
            <span v-else-if="scope.row.userexist==1">{{scope.row.userniname}}
              <el-tag>[虚拟]</el-tag>
              </span>
          </template>

        </el-table-column>
        <el-table-column prop="userimg" label="用户头像" :show-overflow-tooltip="true">
          <template slot-scope="scope"  >
            <el-image  fit="scaleDown"
                       :src="scope.row.userimg" :preview-src-list="[scope.row.userimg]">
            </el-image>
          </template>
        </el-table-column>
        <el-table-column prop="gender" label="性别" :show-overflow-tooltip="true">
          <template slot-scope="scope"  >
            <span v-if="scope.row.gender==1">男</span>
            <span v-else-if="scope.row.gender==2">女</span>
            <span v-else>-</span>
          </template>

        </el-table-column>

        <el-table-column prop="content" label="内容"  :show-overflow-tooltip="true" min-width="200">



        </el-table-column>
        <el-table-column prop="pictureaddr" label="图片" :show-overflow-tooltip="true" width="120">
          <template slot-scope="scope"  >
            <el-image  fit="scaleDown" v-for="item in scope.row.pictureaddr.split(',')"
                       :src="item" :preview-src-list="[item]">
            </el-image>
          </template>
        </el-table-column>
        <el-table-column prop="creationaddr" label="位置" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="viewstatus" label="查看权限" :show-overflow-tooltip="true">
          <template slot-scope="scope"  >
            <el-tag v-if="scope.row.viewstatus==0">公开</el-tag>
            <el-tag v-else-if="scope.row.viewstatus==1">主页可见</el-tag>
            <el-tag v-else-if="scope.row.viewstatus==2">陌生人可见</el-tag>
            <el-tag v-else-if="scope.row.viewstatus==3">自己可见</el-tag>
            <el-tag v-else-if="scope.row.viewstatus==4">关注可见</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="replystatus" label="评论权限" :show-overflow-tooltip="true">
          <template slot-scope="scope"  >
            <el-tag v-if="scope.row.replystatus==0">公开</el-tag>
            <el-tag v-else-if="scope.row.replystatus==1">我关注的人可评论</el-tag>
            <el-tag v-else-if="scope.row.replystatus==2">关注可评论</el-tag>
            <el-tag v-else-if="scope.row.replystatus==3">禁止评论</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="audit" label="状态" >
          <template slot-scope="scope" >
            <el-switch
              v-model="scope.row.audit==0"
              :active-value="true"
              :inactive-value="false"
              active-text="正常"
              inactive-text="封禁"
              @change="change(scope.row)"
            />
          </template>
        </el-table-column>
        <el-table-column prop="visitcount" label="浏览" ></el-table-column>
        <el-table-column prop="dzcount" label="点赞" ></el-table-column>
        <el-table-column prop="replycount" label="回复" ></el-table-column>

        <el-table-column prop="creationtime" label="发布时间" width="160px"></el-table-column>

        <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
          <template slot-scope="scope">
            <el-button type="text"  v-if="queryForm.userexist==1" size="small" @click="deleteHandle(scope.row.cid)">删除</el-button>
            <el-button type="text"  size="small" @click="detail(scope.row.cid)">查看</el-button>

          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="tableForm.pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="tableForm.pageSize"
        :total="tableForm.total"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </el-card>
    <!-- 表单弹窗, 新增数据和修改数据 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <detail ref="detail" @refreshDataList="getDataList"></detail>
  </div>
</template>

<script>
  import AddOrUpdate from './friendscircle-add-and-update.vue'
  import detail from './detail.vue'
  import api from '@/api/api'
  import {checkPermi} from "@/utils/permission";
  import * as systemAdminApi from '@/api/systemadmin'
  import Cookies from 'js-cookie'

  export default {
    components: {
      AddOrUpdate,detail
    },
    data () {
      return {
        listData:[],
        dataList: [],
        queryForm: {
          userniname: '',
          audit: '',
          adminid:'',
          userexist:0
        },
        tableForm:{
          pageIndex: 1,
          pageSize: 10,
          total: 0,
        },
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    mounted () {
      this.getDataList()
      this.handleGetAdminList()
    },
    methods: {
      checkPermi,
      // 每页数
      sizeChangeHandle (val) {
        this.tableForm.pageSize = val
        this.tableForm.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.tableForm.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      search(){
        this.tableForm.pageIndex = 1
        this.getDataList()
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.dataListLoading = true
        let postData={
          'order':'desc',
          'column':'cid'
        }
        Object.assign(postData,this.queryForm, this.tableForm)
        postData.userniname=api.getLikeValue2( postData.userniname);

        if (postData.userexist==1){
          let JavaInfo = JSON.parse(Cookies.get('JavaInfo'))
          postData.adminid=JavaInfo.id;
        }
        api.post('rest/vabc/friendsCircle/list',postData).then(res => {
          this.dataList=res.datalist
          this.tableForm.total=res.total
        }).finally(() => {
          this.dataListLoading = false
        });
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          let JavaInfo = JSON.parse(Cookies.get('JavaInfo'))
          this.$refs.addOrUpdate.init(id,JavaInfo.id)
        })
      },
      detail(id){
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.detail.init(id)
        })
      },
      change(row){
        let postData={cid:row.cid}
        postData.audit=row.audit==1?0:1;
        api.post('rest/vabc/friendsCircle/updateById',postData).then(res => {
          this.$message.success("操作成功")
          row.audit=postData.audit
          // this.getDataList()
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.cid
        })
        this.$confirm(`您确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let postData={ids:ids.join(',')};
          api.post('rest/vabc/friendsCircle/delete',postData).then(res => {
            this.$message.success("删除成功")
            this.getDataList()
          })
        })
      },
      handleGetAdminList() {
        systemAdminApi.adminList(  ).then(data => {
          // data.list[0]
          data.total=data.total-1
          let list=data.list;
          list.splice(0, 1);
          this.listData = list
         // console.error(this.listData)
          // this.handlerGetMenuList()
        })
      },
    }
  }
</script>
